import HTTP from '@/api/http'
import { ENUM } from './enum.js'

const common = {
	install: function(Vue) {
		Vue.prototype.$common = this
	},
	
	msg(title, duration=1500, mask=false, icon='none') {
		//统一提示方便全局修改
		if(Boolean(title) === false){
			return;
		}
		uni.showToast({
			title,
			duration,
			mask,
			icon
		})
	},
	onBack(n=1) {
		uni.navigateBack({
			delta: n
		})
	},
	
	getUrlName(url, name) {
		let r = new RegExp('(\\?|#|&)' + name + '=([^&#]*)(&|#|$)')
		let m = url ? url.match(r) : location.href.match(r)
		return decodeURIComponent(!m ? '' : m[2])
	},
	
	setClipboardData(data) {
		uni.setClipboardData({
			data: data,
			success(res) {
				uni.showToast({
					title: '复制成功',
					icon: 'none'
				})
			},
			fail(err) {
				uni.showToast({
					title: '复制失败',
					icon: 'none'
				})
			}
		})
	},
	
	openPage(url, type) {
		if (type === 'switch') {
			uni.switchTab({
				url
			})
		} else {
			uni.navigateTo({
				url
			})
		}
	},
	
	// return 登录后userinfo
	getUserInfo() {
	},
	
	// 回到顶部
	scrollTop(top = 0) {
		uni.pageScrollTo({
			scrollTop: top,
			duration: 0
		})
	}
	
}

export default common
